<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="30%">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="类型" prop="payFullSendType">
      <el-radio v-model="dataForm.payFullSendType" :label="1">1:1</el-radio>
      <el-radio v-model="dataForm.payFullSendType" :label="2">2:1</el-radio>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dialogImageUrl: '',
        dialogVisible: false,
        dataForm: {
          id: 0,
          payFullSendType: ''
        },
        dataRule: {
          payFullSend: [
            { required: true, message: '分类名称不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id, payFullSend) {
        this.dataForm.id = id || 0
        if (payFullSend === '100-50') {
          this.dataForm.payFullSendType = 2
        } else if (payFullSend === '100-100') {
          this.dataForm.payFullSendType = 1
        }
        this.visible = true
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/user/business/modifyPayFullSendById/${this.dataForm.id}/${this.dataForm.payFullSendType}`),
              method: 'post',
              data: this.$http.adornData()
            }).then(({data}) => {
              let s = JSON.parse(data.data)
              if (data && s.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(s.message)
              }
            })
          }
        })
      }
    }
  }
</script>
